//package com.yunhe.option.controller.data;
//
//import com.yunhe.option.domain.data.SeasonPriceDetail;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.DomainList;
//import com.yunhe.common.model.ResultObject;
//import com.yunhe.option.service.data.SeasonPriceDetailService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.format.annotation.DateTimeFormat;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Date;
//import java.util.Optional;
//
//@Api(value = "SeasonPriceDetail", description = "季节电价详情维护", tags = {"Data_SeasonPriceDetail"})
//@RestController
//@RequestMapping("/prices/cost/season")
//public class SeasonPriceDetailController {
//    @Autowired
//    private SeasonPriceDetailService seasonPriceDetailService;
//
//    @ApiOperation("新增季节电价详情")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "seasonPriceId", value = "季节电价详情ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{seasonPriceId}/detail", method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(@PathVariable("seasonPriceId") Long seasonPriceId,
//                                             @RequestBody SeasonPriceDetail seasonPricedetail)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        SeasonPriceDetail newSeasonPriceDetail = seasonPriceDetailService.create(seasonPricedetail, seasonPriceId);
//        return new ResponseEntity<>(new ResultObject(newSeasonPriceDetail), HttpStatus.OK);
//    }
//
//    @ApiOperation("批量新增季节电价详情")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "seasonPriceId", value = "季节电价详情ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{seasonPriceId}/detail/batch", method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> batchPost(@PathVariable("seasonPriceId") Long seasonPriceId,
//                                                  @RequestBody DomainList<SeasonPriceDetail> details)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        Iterable<SeasonPriceDetail> newSeasonPriceDetail = seasonPriceDetailService.create(details.getList(), seasonPriceId);
//        return new ResponseEntity<>(new ResultObject(newSeasonPriceDetail), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据ID删除季节电价详情")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "季节电价详情ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/detail/{id}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> delete(@PathVariable("id") Long id)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        seasonPriceDetailService.delete(id);
//        return new ResponseEntity<>(new ResultObject(null), HttpStatus.OK);
//    }
//
//    @ApiOperation("更新季节电价详情（全部字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "季节电价详情ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/detail/{id}", method =  RequestMethod.PUT)
//    public ResponseEntity<ResultObject> put(@PathVariable("id") Long id,
//                                            @RequestBody SeasonPriceDetail seasonPriceDetail)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        seasonPriceDetail.setId(id);
//        SeasonPriceDetail newSeasonPriceDetail = seasonPriceDetailService.update(seasonPriceDetail);
//        return new ResponseEntity<>(new ResultObject(newSeasonPriceDetail), HttpStatus.OK);
//    }
//
//    @ApiOperation("更新季节电价详情（更新指定字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "季节电价详情ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "title", value = "地区标题", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "runMonth", value = "适用月份", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "priceRates", value = "电价费率", dataType = "string", paramType = "query")
//    })
//    @RequestMapping(value = "/{seasonPriceId}/detail/{seasonPriceDetailId}", method =  RequestMethod.PATCH)
//    public ResponseEntity<ResultObject> patch(@PathVariable("seasonPriceId") Long seasonPriceId,
//                                              @PathVariable("seasonPriceDetailId") Long seasonPriceDetailId,
//                                              @RequestParam("price") Optional<Double> price,
//                                              @RequestParam("startTime") @DateTimeFormat(pattern = "HH:mm:ss") Optional<Date> startTime,
//                                              @RequestParam("endTime") @DateTimeFormat(pattern = "HH:mm:ss") Optional<Date> endTime)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        SeasonPriceDetail newSeasonPriceDetail = seasonPriceDetailService.update(seasonPriceId, seasonPriceDetailId,
//                price.orElse(null), startTime.orElse(null), endTime.orElse(null));
//        return new ResponseEntity<>(new ResultObject(newSeasonPriceDetail), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据条件获得季节电价详情列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "seasonPriceId", value = "季节电价ID", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "priceRateCode", value = "电价费率CODE", dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/detail", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> search(@RequestParam("seasonPriceId") Optional<Long> seasonPriceId,
//                                               @RequestParam("priceRateCode") Optional<Long> priceRateCode)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException{
//        Iterable<SeasonPriceDetail> newSeasonPriceDetail =
//                seasonPriceDetailService.search(seasonPriceId.orElse(null), priceRateCode.orElse(null));
//        return new ResponseEntity<>(new ResultObject(newSeasonPriceDetail), HttpStatus.OK);
//    }
//
//    @ApiOperation("根据季节电价ID和电价费率CODE删除季节电价详情")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "seasonPriceId", value = "季节电价ID", required = true, dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "priceRateCode", value = "电价费率CODE", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/detail", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> deleteOnePriceRate(@RequestParam("seasonPriceId") Optional<Long> seasonPriceId,
//                                                           @RequestParam("priceRateCode") Optional<Long> priceRateCode)
//            throws ArgumentErrorException {
//        seasonPriceDetailService.deleteBySeasonPriceIdAndPriceRateCode(seasonPriceId.get(), priceRateCode.get());
//        return new ResponseEntity<>(new ResultObject(null), HttpStatus.OK);
//    }
//}
